package com.rui.common.util;

import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Encoder;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;


/**
 * 加密工具类
 *
 * @author xr
 * @email xr@qq.com
 * @date 2020-01-01 00:00:00
 */
@Slf4j
public class EncodeUtil {
    /**
     * MD5加密
     *
     * @param str
     * @return
     */
    public static String encode(String str) {
        String s = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            s = base64en.encode(md5.digest(str.getBytes(StandardCharsets.UTF_8)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
    }

    public static void main(String[] args) {
        System.out.println(encode("123456"));
    }
}